#ifndef SH_TIME_ELAPSEDTIMER_HPP
#define SH_TIME_ELAPSEDTIMER_HPP

#include "timestamp.hpp"

namespace sh {
	

class ElapsedTimer {
public:
	ElapsedTimer() : time{} { start(); }
	~ElapsedTimer() = default;

	void start();
	int64_t restart();
	int64_t elapsed() const;
	bool hasExpired(int64_t timeout) const;

private:
	int64_t time;
};


/*
* //////////////////////////////////////////////////////////////////////////////////////////
*
*
*
* //////////////////////////////////////////////////////////////////////////////////////////
*/


inline void ElapsedTimer::start()
{
	time = timestamp::steady_ms();
}

inline int64_t sh::ElapsedTimer::restart()
{
	auto interval = time;
	start();
	return time - interval;
}

inline int64_t sh::ElapsedTimer::elapsed() const
{
	return timestamp::steady_ms() - time;
}

inline bool ElapsedTimer::hasExpired(int64_t timeout) const
{
	return elapsed() > timeout;
}

} // namespace sh

#endif // SH_TIME_ELAPSEDTIMER_HPP